package coms.action;

import coms.delegates.ConferenceDelegate;
import coms.delegates.ConferenceRegistrationDelegate;
import coms.dto.Conference;
import coms.dto.ConferenceRegistration;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.PaymentModel;

public class PaymentAction extends ComsActionSupport {

    private String conferenceBookingId;
    private List<PaymentModel> payment;
    private ConferenceRegistrationDelegate conRegDel;
    private ConferenceDelegate conDel;

    public PaymentAction() {
        conRegDel = new ConferenceRegistrationDelegate();
        conDel=new ConferenceDelegate();
    }
            
    public List<PaymentModel> getPayment() {
        return payment;
    }

    public void setPayment(List<PaymentModel> payment) {
        this.payment = payment;
    }
    

    public String getConferenceBookingId() {
        return conferenceBookingId;
    }

    public void setConferenceBookingId(String conferenceBookingId) {
        this.conferenceBookingId = conferenceBookingId;
    }

    public String confirm() {
        
        ConferenceRegistration conReg = conRegDel.getById(Integer.parseInt(conferenceBookingId));
        conReg.setPaymentStatus(true);
        conRegDel.update(conReg);
        return SUCCESS;
    }

    public String manage() {
        List<Conference> conf=conDel.findAll();
        payment=new ArrayList<PaymentModel>();         
        
        System.out.println(conf.size());
        
        for(Conference c:conf)
        {
            PaymentModel ps=new PaymentModel();
            ps.setId(c.getId());
            ps.setName(c.getName());
            ps.setConferenceDate(c.getConferenceStartDateStr());
            ps.setCost(c.getCost());
            ps.setRegistrationEndDate(c.getRegistrationEndDateStr());            
            ps.setRegistrationStartDate(c.getRegistrationStartDateStr());            
            List<ConferenceRegistration> confRegList=conRegDel.getByConference(c);            
            ps.setRegisteredUsers(confRegList.size());
            int no=0;
            for(ConferenceRegistration d:confRegList)
            {
                if(d.isPaymentStatus())                
                {
                    no++;
                }
            }            
            ps.setPaidUsers(no);           
            payment.add(ps);
        }
        return "manage";
    }
}
